package com.xian.daoimpl;

import java.util.List;

import org.hibernate.Query;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.xian.dao.GreensDao;
import com.xian.domain.Greens;

public class GreensDaoImpl extends HibernateDaoSupport implements GreensDao{

	@Override
	public void addupGreens(Greens greens) {
		this.getHibernateTemplate().save(greens);
		
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Greens> findGreensPage(int pages) {
		Object[] objects ={(pages-1)*Greens.PANGESIZE,Greens.PANGESIZE};
		return getHibernateTemplate().find("from Greens ");
	}

	@Override
	public int findGreenscount() {
		// TODO Auto-generated method stub
		int n = 0;
		Query query = this.getSession().createQuery("select count(*) from Greens");
		 n = new Integer(((Long) query.uniqueResult()).toString());
		return n;
	}

	@Override
	public List<Greens> findGreensSort(String hql) {
		
		return getHibernateTemplate().find(hql);
	}

	@Override
	public void updateGreens(Greens greens) {
		
		this.getHibernateTemplate().update(greens);
		
	}

	@Override
	public void deleteGreens(Greens greens) {
		// TODO Auto-generated method stub
		this.getHibernateTemplate().delete(greens);
	}

	

}
